import { ITabe } from '../type/index'

export type TabsState = {
    tabsList: Array<ITabe>
}
// 定义state
export const state: TabsState = {
    tabsList: []
}

// 定义mutations
export const mutations = {
    addTabe: (state: TabsState, tab: ITabe) => {
        // 判断是否已经存在,如果不存在,才放入
        // console.log(state.tabsList)
        // console.log(tab)
        if(state.tabsList.some(item => item.path === tab.path)) return
        if(!tab.hidden) {
            state.tabsList.push(tab)
        }
        // state.tabsList.push(tab)
    }
}

// 定义actions
export const actions = {

}

// 定义getters
export const getters = {
    // 获取tabs
    getTabs: (state: TabsState) => {
        // console.log(state.tabsList)
        return state.tabsList
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}